import re
import json
import os

print(os.path.dirname(os.path.abspath(__file__)))


genres = {}

with open(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "GenreList.txt"),
    "r",
    encoding="utf-8-sig",
) as file:
    for line in file:
        if line != "\n":
            text = re.sub(r"\[.+|\]", "", line)
            subgenre, genre = text.split(" | ")
            subgenre = subgenre.rstrip().lstrip()
            genre = genre.replace("\n", "").rstrip().lstrip()
            if genre not in genres:
                genres[genre] = []
            genres[genre] += [subgenre]

with open("GenreList.json", "w", encoding="utf-8-sig") as file:
    json.dump(genres, file, indent=4)
